package com.qf.user.info.controller;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.qf.common.entity.User;
import com.qf.common.vo.R;
import com.qf.user.info.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.SerializationUtils;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author dong_
 * @since 2023-07-04
 */
@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    IUserService userService;

    @GetMapping("/get/{id}")
    public R getUserById(@PathVariable("id") Integer id){
        User user = userService.getById(id);
        return R.ok(user);
    }

    @PostMapping("/add")
    public R addUser(@RequestBody User user){
        userService.save(user);
        return R.ok(user);
    }


    @PostMapping("/update")
    public R updateUser(User user){
        userService.updateById(user);
        return R.ok();
    }

    @DeleteMapping("/del/{id}")
    public R deleteUser(@PathVariable("id") Integer id){
        userService.removeById(id);
        return R.ok();
    }


}
